/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.casestudy1.view;

import com.casestudy1.main.MainMidlet;
import com.sun.lwuit.Button;
import com.sun.lwuit.CheckBox;
import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Command;
import com.sun.lwuit.ComponentGroup;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Tabs;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.animations.Transition;
import com.sun.lwuit.animations.Transition3D;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;

/**
 *
 * @author Windsea
 */
public class Setting extends View {

    Tabs tab;
    Command backCommand;
    private Button btnReset;
    private ComboBox ThemeBox;
    private CheckBox rotateCheckBox;

    public Setting(final MainMidlet midlet) {
        super(midlet);
        setTitle("Setting");
//        setTransitionOutAnimator(CommonTransitions.createSlide(
//                CommonTransitions.SLIDE_VERTICAL, true, 2000));
        setTransitionInAnimator(Transition3D.createRotation(250, true));
        setScrollable(false);
        tab = new Tabs();
        tab.setHeight(300);
        ThemeBox = new ComboBox();

        ThemeBox.addItem("Default Theme");
        ThemeBox.addItem("Windsea Theme");
        ThemeBox.addItem("Wood Theme");
        ThemeBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                midlet.setThemeName(ThemeBox.getSelectedItem().toString());
//                midlet.setThemeRecord(ThemeBox.getSelectedItem().toString());
            }
        });

        btnReset = new Button("Apply Theme");
        btnReset.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                
                if (!midlet.getThemeName().equals("")) {
//                    setTheme(midlet.getThemeName());
                    midlet.setThemeRecord(midlet.getThemeName());
                    Dialog.show(midlet.getThemeRecordname(),null,Dialog.TYPE_INFO, midlet.getImage(midlet.getThemeRecordname()), "OK", null);
                }

//                midlet.startApp();
            }
        });

        ComponentGroup themeboxgr = new ComponentGroup();
        themeboxgr.addComponent(ThemeBox);
        themeboxgr.addComponent(btnReset);
        ComponentGroup othergroup = new ComponentGroup();
        rotateCheckBox = new CheckBox("Lock Screen Rotate");
        othergroup.addComponent(rotateCheckBox);
        if (Display.getInstance().canForceOrientation() == false) {
            rotateCheckBox.setEnabled(false);
        }
//        othergroup.setLayout(new FlowLayout());
        rotateCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                if (rotateCheckBox.isSelected() && Display.getInstance().canForceOrientation() == true) {
                    Display.getInstance().lockOrientation(true);
//                    midlet.displayOrientationChanged(Orientation.ORIENTATION_LANDSCAPE);
                } else {
                    Display.getInstance().lockOrientation(false);
//                    midlet.displayOrientationChanged(Orientation.ORIENTATION_PORTRAIT);
                }
            }
        });
        backCommand = new Command("Back") {
            public void actionPerformed(ActionEvent evt) {
                midlet.showLoginForm();
            }
        };

        tab.setSwipeActivated(true);
        tab.setTabPlacement(Tabs.TOP);
        tab.addTab("Sounds", null);
        tab.addTab("Themes", themeboxgr);
        tab.addTab("Others", othergroup);
        addComponent(tab);
        addCommand(backCommand);
        setBackCommand(backCommand);
    }
}
